package com.ruoyi.fetv.controller.userController.context;

import com.ruoyi.common.aspect.annotation.AutoDict;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.fetv.controller.userController.context.vo.RequestVO;
import com.ruoyi.fetv.controller.vo.navigation.RespVO;
import com.ruoyi.fetv.domain.FetvNavigationContext;
import com.ruoyi.fetv.service.IFetvNavigationContextService;
import com.ruoyi.fetv.util.Constant;
import com.ruoyi.fetv.util.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 栏目Controller
 *
 * @author Jack
 * @date 2023-03-07
 */
@Api(value = "/v1/fetv/context", tags = {"用户获取栏目信息"})
@RestController
@RequestMapping("/v1/fetv/context")
@Validated
@AutoDict
public class NavigationContextController extends BaseController {
    @Autowired
    private IFetvNavigationContextService fetvNavigationContextService;

    /**
     * 查询栏目列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = RequestVO.class, name = "UserNavigationContextRequestVO", value = "栏目参数", required = true)
    })
    @ApiOperation(value = "查询栏目列表", notes = "查询栏目列表", httpMethod = "GET")
    @GetMapping("/list")
    @ApiResponse(code = 200, message = "", response = TableDataInfo.class)
    public TableDataInfo<List<com.ruoyi.fetv.controller.userController.context.vo.RespVO>> list(RequestVO requestVO) {
        startPage();
        FetvNavigationContext fetvNavigationContext = (FetvNavigationContext) Convert.convert(requestVO, FetvNavigationContext.class);
        fetvNavigationContext.setStatus(Constant.ENABLE);
        List<RespVO> list = fetvNavigationContextService.selectFetvNavigationContextList(fetvNavigationContext);
        Convert.covertList(list, RespVO.class, com.ruoyi.fetv.controller.userController.context.vo.RespVO.class);
        return getDataTable(list);
    }

    /**
     * 获取栏目详细信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", required = true)
    })
    @ApiOperation(value = "获取栏目详细信息", notes = "获取栏目详细信息", httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code = 200, message = "", response = com.ruoyi.fetv.controller.userController.context.vo.RespVO.class),
            @ApiResponse(code = 403, message = "请不要越权", response = String.class)
    })
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        RespVO data = fetvNavigationContextService.selectFetvNavigationContextById(id);
        Convert.convert(data, com.ruoyi.fetv.controller.userController.context.vo.RespVO.class);
        if (Objects.equals(data.getStatus(), Constant.ENABLE)) {
            return success(data);
        }
        throw new ServiceException("请不要越权");
    }

    /**
     * 查询父或子栏目列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = RequestVO.class, name = "UserNavigationRequestVO", value = "栏目参数", required = true)
    })
    @ApiOperation(value = "查询主栏目列表", notes = "查询主栏目列表", httpMethod = "GET")
    @ApiResponse(code = 200, message = "", response = com.ruoyi.fetv.controller.userController.context.vo.RespVO.class)
    @PreAuthorize("@ss.hasPermi('fetv:context:list')")
    @GetMapping("/list/primary")
    public TableDataInfo listPrimary(FetvNavigationContext fetvNavigationContext) {
        startPage();
        fetvNavigationContext.setStatus(Constant.ENABLE);
        List<RespVO> list = fetvNavigationContextService.selectFetvNavigationContextListLevel(fetvNavigationContext);
        Convert.covertList(list, RespVO.class, com.ruoyi.fetv.controller.userController.context.vo.RespVO.class);
        return getDataTable(list);
    }
}
